﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using DevComponents.DotNetBar.Metro;
using ProductManagement.CrystalReports;
using ProductManagement;

namespace ProductManagement.Presentation_Layer
{
    public partial class ReportForm : MetroForm
    {
        private int _rid;
        private string _task;
        private ProductManagementClassesDataContext db = new ProductManagementClassesDataContext();

        public ReportForm(int reportID, string reportTask)
        {
            _rid = reportID;
            _task = reportTask;
            InitializeComponent();
        }

        private void ReportForm_Load(object sender, EventArgs e)
        {
            var reportDetails = db.sp_GetCrystalReportDataSource(_rid).ToList();
            
            if (_task.ToLower().Contains("nhập"))
            {
                ImportReport importReport = new ImportReport();
                importReport.SetDataSource(reportDetails);
                crystalReportViewer1.ReportSource = importReport;
                crystalReportViewer1.Refresh();
            }
            else
            {
                ExportReport exportReport = new ExportReport();
                exportReport.SetDataSource(reportDetails.ToList());
                crystalReportViewer1.ReportSource = exportReport;
                crystalReportViewer1.Refresh();
            }
        }
    }
}
